<div id="app">
    <admin-page-header back>
        <bi-button type="primary" @click="save">保存</bi-button>
    </admin-page-header>

    <div class="container">
        <div class="row">
            <div class="col-12">
                <bi-card>
                    <bi-form ref="form">
                        <bi-form-item label="标题">
                            <bi-input v-model="form.title" placeholder="请输入标题" required />
                        </bi-form-item>
                        <web-model-param ref="param" :model="$pageData.model_id"  :data="value" ></web-model-param>
                    </bi-form>
                    <template #footer>
                        <bi-button type="primary" @click="save">保存</bi-button>
                    </template>
                </bi-card>
            </div>
        </div>
    </div>
</div>

<script>
import webModelParam from 'field/model-param.vue';
let app = admin.createApp({
    components:{
        webModelParam,
    },
    data(){
        let form = {
            blockitem_id:'',
            title:'',
        }

        this.$assign(form, this.$pageData.item);

        let value  = {};
        if (this.$pageData.value) value = this.$pageData.value;
        return {
            form,
            value
        }
    },
    methods:{
        save(){
            if (this.$refs.form.check()){
                this.$ajax({
                    url:this.$url({action:'ItemSave'}),
                    data:{
                        block_id:this.$pageData.block_id,
                        ...this.form,
                        value:this.$refs.param.getData()
                    },
                    success:(res)=>{
                        this.$user.delLocalStorage('web-part-input');
                        this.$go(-1);
                    }
                });
            }
        }
    }
}).mount('#app');
</script>